package cn.com.pansky.action.homePage;

import java.io.File;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import net.vsame.url2sql.action.CommonAction;
import net.vsame.url2sql.helper.SqlHelper;
import net.vsame.url2sql.sql.Model;
import cn.com.pansky.action.logs.Log;
import cn.com.pansky.sdk.API;
import cn.com.pansky.util.ImageBinaryUtil;

import com.alibaba.fastjson.JSONObject;


/**
 * 我要参保
 * @author 王润华
 *
 */
public class InsuredAction extends CommonAction {
	private Log log = new Log();
	/**
	 * 参保
	 */
	public void insured(){
		String CA001 = getParam("CA001");
		//日志记录start
		String AF001 = log.start(CA001, "CB");
		//获取前端页面手动填写内容
		String AAB301 = getParam("AAB301");//所属行政区代码.常住地址
		String AAZ070 = getParam("AAZ070");//社区ID
		String AAC009 = getParam("AAC009");//户口性质
		String AAC012 = getParam("AAC012");//个人身份
		String AAE004 = getParam("AAE004");//联系人姓名
		String AAE005 = getParam("AAE005");//联系电话
		
		String AAE006 = getParam("AAE006");//地址
		String AAE159 = "";//联系电子邮箱
		
		String BIC105 = getParam("BIC105");//户口本照片
		String path1 = BIC105;
		String BIC104 = getParam("BIC104");//身份证反面照片
		String path2 = BIC104;
		String BIC106 = getParam("BIC106");//身份证正面照片
		String path3 = BIC106;
		BIC105 = ImageBinaryUtil.getImageBinary(BIC105);
		BIC104 = ImageBinaryUtil.getImageBinary(BIC104);
		BIC106 = ImageBinaryUtil.getImageBinary(BIC106);
		File file1 = new File(path1);
		File file2 = new File(path2);
		File file3 = new File(path3);
		file1.delete();
		file2.delete();
		file3.delete();
//		String AAZ003 = getParam("AAZ003");//当事人银行账号ID
		String AAZ289 = getParam("AAZ289");//征缴规则参数ID
//		String AAZ065 = getParam("BAB502");//银行类别
		//获取注册信息中已有数据
		String queryInfo = urlConfig.getVar("queryInfo");
		Model model = SqlHelper.queryOne(queryInfo,CA001);
		
		String AAC002 = model.getString("CA006");//公民身份号码
		String AAC003 = model.getString("CA003");//姓名
		String AAC004 = model.getString("CA050");//性别
		String AAC005 = model.getString("CA051");//民族
		String AAC006 = model.getString("CA009");//出生日期
		String AAC010 = model.getString("CA052");//户口所在地址
		
		JSONObject param = new JSONObject();
		param.put("AAA121", "A20001");//业务类型是查询参保	
		param.put("AAB301", AAB301);
		param.put("AAZ070", AAZ070);
		param.put("AAC009", AAC009);
		param.put("AAC010", AAC010);
		param.put("AAC012", AAC012);
		param.put("AAE004", AAE004);
		param.put("AAE005", AAE005);
		param.put("AAE006", AAE006);
		param.put("AAE159", AAE159);
		param.put("AAC002", AAC002);
		param.put("AAC003", AAC003);
		param.put("AAC004", AAC004);
		param.put("AAC005", AAC005);
		param.put("AAC006", AAC006);
		param.put("BIC104", BIC104);//身份证照片
		param.put("BIC105", BIC105);//户口本照片
		param.put("BIC106", BIC106);//户口本照片
		param.put("AAZ003", "");//当事人银行账号ID
		param.put("AAZ289", AAZ289);//征缴规则参数ID
		param.put("AAZ065", "");//征缴规则参数ID
		Date date=new Date();
		DateFormat format=new SimpleDateFormat("yyyyMMdd");
		String time=format.format(date);
		param.put("AAE030", time);//参保时间
		
		String userId = user.getString("AA001");
		param.put("AAE011", userId);
		JSONObject result = API.sendController("insuredRegistrationController.json",param);
		Boolean success = result.getBoolean("SUCCESS");
		
		datas.put("isPass", success);
		datas.put("info", result.getString("MSG"));
		
		//日志记录end
		boolean result2 = log.end(AF001, datas.get("isPass"), datas.get("info"));
		System.out.println("日志：参保"+result2);

		context.getDatas().put("result", datas);
	}
}
